package com.py.unit.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.core.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.py.unit.domain.PyAccount;
import com.py.unit.mapper.PySuppliersMapper;
import com.py.unit.domain.PySuppliers;
import com.py.unit.service.IPySuppliersService;

import javax.annotation.Resource;

/**
 * 供应商信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-20
 */
@Service
public class PySuppliersServiceImpl implements IPySuppliersService 
{
    @Resource
    private PySuppliersMapper pySuppliersMapper;

    /**
     * 查询供应商信息
     * 
     * @param supplierId 供应商信息主键
     * @return 供应商信息
     */
    @Override
    public PySuppliers selectPySuppliersBySupplierId(Long supplierId)
    {
        return pySuppliersMapper.selectPySuppliersBySupplierId(supplierId);
    }

    /**
     * 查询供应商信息列表
     * 
     * @param pySuppliers 供应商信息
     * @return 供应商信息
     */
    @Override
    public List<PySuppliers> selectPySuppliersList(PySuppliers pySuppliers)
    {
        return pySuppliersMapper.selectPySuppliersList(pySuppliers);
    }



    /**
     * 新增供应商信息
     * 
     * @param pySuppliers 供应商信息
     * @return 结果
     */
    @Transactional
    @Override
    public int insertPySuppliers(PySuppliers pySuppliers, PyAccount pyAccount)
    {
        int rows =0;
        rows= pySuppliersMapper.insertPySuppliers(pySuppliers);
        rows=pySuppliersMapper.insertPyAccount(pyAccount);
        return rows;
    }
    /**
     * 修改供应商信息
     * 
     * @param pySuppliers 供应商信息
     * @return 结果
     */
    @Transactional
    @Override
    public int updatePySuppliers(PySuppliers pySuppliers )
    {
        int update=0;
           pySuppliers.setIsDeleted(0);
        update=pySuppliersMapper.updatePySuppliers(pySuppliers);
        System.out.println("进来这"+pySuppliers.getPyAccount());
        update=pySuppliersMapper.uppdatePyaccount(pySuppliers.getPyAccount());
        System.out.println(update);
        return update;
    }
    /**
     * 批量删除供应商信息
     * 
     * @param supplierIds 需要删除的供应商信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deletePySuppliersBySupplierIds(Long[] supplierIds)
    {
        System.out.println("supperIDs:"+supplierIds);
//        pySuppliersMapper.deletePyAccountBySourceUnits(supplierIds);
        return pySuppliersMapper.deletePySuppliersBySupplierIds(supplierIds);
    }
    /**
     * 删除供应商信息信息
     * 
     * @param supplierId 供应商信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deletePySuppliersBySupplierId(Long supplierId)
    {
        pySuppliersMapper.deletePyAccountBySourceUnit(supplierId);
        return pySuppliersMapper.deletePySuppliersBySupplierId(supplierId);
    }

    @Override
    public int insSupAcc(PySuppliers pySuppliers) {
        System.out.println("adaha:"+pySuppliers);
        int add=0;
        pySuppliers.setIsDeleted(0);//0未删除
        add= pySuppliersMapper.insertPySuppliers(pySuppliers);
        add= pySuppliersMapper.insertPyAccount(pySuppliers.getPyAccount());
        System.out.println(add);
        return add;
    }

    /**
     * 查所有(不分页)
     * @return
     */
    @Override
    public List<PySuppliers> selectAll() {
        return pySuppliersMapper.selectAll();
    }

    @Override
    public int delPuuAccList(Integer[] supplierId) {
        pySuppliersMapper.deletePySuppliersBySupplierCode(supplierId);
        return pySuppliersMapper.deletePyAccountBySourceUnitCode(supplierId);
    }

    /**
     * 新增财务信息信息
     *
     * @param pySuppliers 供应商信息对象
     */
    public void insertPyAccount(PySuppliers pySuppliers)
    {
        List<PyAccount> pyAccountList = pySuppliers.getPyAccountList();
        Long supplierId = pySuppliers.getSupplierId();
        if (StringUtils.isNotNull(pyAccountList))
        {
            List<PyAccount> list = new ArrayList<PyAccount>();
            for (PyAccount pyAccount : pyAccountList)
            {
                pyAccount.setSourceUnit(String.valueOf(supplierId));
                list.add(pyAccount);
            }
            if (list.size() > 0)
            {
                pySuppliersMapper.batchPyAccount(list);
            }
        }
    }
}
